﻿using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class roleDAL : PageDAL<roleModel>
    {
        public roleModel GetModelByID(string tableName, int pid)
        {
            string sql = $"select * from  {tableName} where id='{pid}'";
            DataTable dt = new DBHelper().GetDataTable(sql);
            roleModel model = new roleModel()
            {
                ID = int.Parse(dt.Rows[0]["id"].ToString()),
                roleName = dt.Rows[0]["roleName"].ToString(),
                Qx  = dt.Rows[0]["QxID"].ToString(),
            };
            return model;
        }

        public DataTable SelectName(string tableName, string mz)
        {
            string sql = $"select * from {tableName} where roleName like '%{mz}%'";
            return new DBHelper().GetDataTable(sql);
        }

        public DataTable SelectLJR(string tableOne, string tableTwo, string mz)
        {
            string sql = $"select * from {tableOne} a,{tableTwo} b where roleName like '%{mz}%' and b.ID=a.{tableTwo}ID";
            return new DBHelper().GetDataTable(sql);
        }
    }
}
